/**
* @file lcd_if_fsmc_mcu8.h
* @brief  lcd interface for FSMC mcu 8bit
* @details 
* @author huangbin
* @version V1.0.0
* @date 2025-04-20
* @copyright All documents are copyrighted by Shenzhen Xinlongwei Technology Co., LTD.
*            They may not be used for commercial purposes without permission
*/
#ifndef __LCD_IF_FSMC_MCU8_H__
#define __LCD_IF_FSMC_MCU8_H__
#include "stdint.h"

#ifdef __cplusplus
 extern "C" {
#endif /* __cplusplus */
////////////////////////////define//////////////////////////////////////
/*
2^26 =0X0400 0000 = 64MB,每个 BANK 有4*64MB = 256MB
64MB:FSMC_Bank1_NORSRAM1:0X6000 0000 ~ 0X63FF FFFF
64MB:FSMC_Bank1_NORSRAM2:0X6400 0000 ~ 0X67FF FFFF
64MB:FSMC_Bank1_NORSRAM3:0X6800 0000 ~ 0X6BFF FFFF
64MB:FSMC_Bank1_NORSRAM4:0X6C00 0000 ~ 0X6FFF FFFF

选择BANK1-BORSRAM4 连接 TFT，地址范围为0X6C00 0000 ~ 0X6FFF FFFF
FSMC_A23 接LCD的DC(寄存器/数据选择)脚
寄存器基地址 = 0X6C00 0000
RAM基地址 = 0X6D00 0000 = 0X6C00 0000+2^23*2 = 0X6C00 0000 + 0X100 0000 = 0X6D00 0000
当选择不同的地址线时，地址要重新计算 
*/

/**
* @brief 用于LCD命令操作的地址
*/
#define      FSMC_ADDR_CMD         ( ( uint32_t ) 0x6C000000 )

/**
* @brief 用于LCD数据操作的地址
*/
#define      FSMC_ADDR_DATA        ( ( uint32_t ) 0x6C000001 )

/**
* @brief 由片选引脚决定的NOR/SRAM块
*/
#define      FSMC_Bank_NORSRAMx           FSMC_Bank1_NORSRAM4

/******************************* pin define ***************************/
//片选，选择NOR/SRAM块
#define      FSMC_MCU8_CS_CLK                RCC_APB2Periph_GPIOA   	//PA7 NE4
#define      FSMC_MCU8_CS_PORT               GPIOA
#define      FSMC_MCU8_CS_PIN                GPIO_Pin_7

//DC引脚，使用FSMC的地址信号控制，本引脚决定了访问LCD时使用的地址
//PB13为FSMC_A0
#define      FSMC_MCU8_DC_CLK                RCC_APB2Periph_GPIOB
#define      FSMC_MCU8_DC_PORT               GPIOB
#define      FSMC_MCU8_DC_PIN                GPIO_Pin_13

//写使能NWE
#define      FSMC_MCU8_WR_CLK                RCC_APB2Periph_GPIOA
#define      FSMC_MCU8_WR_PORT               GPIOA
#define      FSMC_MCU8_WR_PIN                GPIO_Pin_6

//读使能NOE
#define      FSMC_MCU8_RD_CLK                RCC_APB2Periph_GPIOA
#define      FSMC_MCU8_RD_PORT               GPIOA
#define      FSMC_MCU8_RD_PIN                GPIO_Pin_8

//复位引脚
#define      FSMC_MCU8_RST_CLK               RCC_APB2Periph_GPIOB
#define      FSMC_MCU8_RST_PORT              GPIOB
#define      FSMC_MCU8_RST_PIN               GPIO_Pin_12

//背光引脚
#define      FSMC_MCU8_BK_CLK                RCC_APB2Periph_GPIOB
#define      FSMC_MCU8_BK_PORT               GPIOB
#define      FSMC_MCU8_BK_PIN                GPIO_Pin_1


//数据信号线
#define      FSMC_MCU8_D0_CLK                RCC_APB2Periph_GPIOB
#define      FSMC_MCU8_D0_PORT               GPIOB
#define      FSMC_MCU8_D0_PIN                GPIO_Pin_14

#define      FSMC_MCU8_D1_CLK                RCC_APB2Periph_GPIOB   
#define      FSMC_MCU8_D1_PORT               GPIOB
#define      FSMC_MCU8_D1_PIN                GPIO_Pin_15

#define      FSMC_MCU8_D2_CLK                RCC_APB2Periph_GPIOA
#define      FSMC_MCU8_D2_PORT               GPIOA
#define      FSMC_MCU8_D2_PIN                GPIO_Pin_0

#define      FSMC_MCU8_D3_CLK                RCC_APB2Periph_GPIOA
#define      FSMC_MCU8_D3_PORT               GPIOA
#define      FSMC_MCU8_D3_PIN                GPIO_Pin_1

#define      FSMC_MCU8_D4_CLK                RCC_APB2Periph_GPIOA   
#define      FSMC_MCU8_D4_PORT               GPIOA
#define      FSMC_MCU8_D4_PIN                GPIO_Pin_2

#define      FSMC_MCU8_D5_CLK                RCC_APB2Periph_GPIOA
#define      FSMC_MCU8_D5_PORT               GPIOA
#define      FSMC_MCU8_D5_PIN                GPIO_Pin_3

#define      FSMC_MCU8_D6_CLK                RCC_APB2Periph_GPIOA
#define      FSMC_MCU8_D6_PORT               GPIOA
#define      FSMC_MCU8_D6_PIN                GPIO_Pin_4

#define      FSMC_MCU8_D7_CLK                RCC_APB2Periph_GPIOA
#define      FSMC_MCU8_D7_PORT               GPIOA
#define      FSMC_MCU8_D7_PIN                GPIO_Pin_5


//背光
//#if LCD1_BACKLIGHT_TYPE	== LCD1_BACKLIGHT_TYPE_3V3
	#define FSMC_MCU8_BK_OFF()				GPIO_SetBits(FSMC_MCU8_BK_PORT, FSMC_MCU8_BK_PIN)
	#define FSMC_MCU8_BK_ON()				GPIO_ResetBits(FSMC_MCU8_BK_PORT, FSMC_MCU8_BK_PIN)
//#elif 	LCD1_BACKLIGHT_TYPE	== LCD1_BACKLIGHT_TYPE_18V
//	#define FSMC_MCU8_BK_ON()				GPIO_SetBits(FSMC_MCU8_BK_PORT, FSMC_MCU8_BK_PIN)
//	#define FSMC_MCU8_BK_OFF()				GPIO_ResetBits(FSMC_MCU8_BK_PORT, FSMC_MCU8_BK_PIN)
//#endif

//复位
#define FSMC_MCU8_RESET_HIGH()			GPIO_SetBits(FSMC_MCU8_RST_PORT, FSMC_MCU8_RST_PIN)
#define FSMC_MCU8_RESET_LOW()			GPIO_ResetBits(FSMC_MCU8_RST_PORT, FSMC_MCU8_RST_PIN)

/////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif
/************************END OF FILE*************************************/

